package yl.hs.bmipfull.service.dataCockpit.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import yl.hs.bmipfull.daos.production.IProductShipOrderDao;
import yl.hs.bmipfull.daos.production.IProductionTaskDao;
import yl.hs.bmipfull.daos.salemanage.ISaleSystemLogDao;
import yl.hs.bmipfull.pojo.salemanage.CustomerInfoEntity;
import yl.hs.bmipfull.service.dataCockpit.IProjectEngineeringService;
import yl.hs.bmipfull.utils.Tl;
import yl.hs.bmipfull.viewmodels.dataCockpit.EngineeringVo;

import java.util.*;

/**
 * @author 韩纪旺
 * @apiNote
 * @since 2022/9/20 14:53 创建
 */
@Service
public class ProjectEngineeringServiceImpl implements IProjectEngineeringService {

    @Autowired
    IProductionTaskDao taskDao;
    @Autowired
    ISaleSystemLogDao logDao;

    @Autowired
    IProductShipOrderDao orderDao;

    @Override
    public Map<String, Object> getBasicInformation() {
        Map<String, Object> map = new HashMap<>();
        Map<String, Object> query = new HashMap<>();
        query.put("selectMonth", new Date());
        int production = taskDao.getProduction();
        int suspend = taskDao.getSuspend();
        int completed = taskDao.getCompleted();
        //本月
        var nowLogList = logDao.queryListByCondition(query, null);
        long count = nowLogList.stream().filter(t -> t.getTypeCode().equals(Tl.getDBMapCode(CustomerInfoEntity.class))).count();
        //待合作项目工程数量
       int cooperated= taskDao.getToBeCooperated();

       //待合作
       map.put("cooperated",cooperated);
       //新增
        map.put("count", count);
        //生产中
        map.put("production", production);
        //暂停
        map.put("suspend", suspend);
        //已完结
        map.put("completed", completed);
        //合作工程数量
        map.put("pscSum", production + suspend + completed);
        return map;


    }

    @Override
    public Map<Object,Object> weightAnalysis() {
        List<EngineeringVo> engineeringVos = orderDao.weightAnalysis();
        Map<Object,Object> map=new HashMap<>();
        List<Object> list =new ArrayList<>();
        List<Object> list1=new ArrayList<>();
        for (EngineeringVo engineeringVo : engineeringVos) {
            list.add(engineeringVo.getName()) ;
            list1.add(engineeringVo.getNetWeight());
        }

        map.put("Name",list);
        map.put("NetWeight",list1);

        return map;

    }

    @Override
    public List<EngineeringVo> customerRanking(String timeType) {
        return orderDao.customerRanking(timeType);
    }

    @Override
    public List<EngineeringVo> regionalDelivery() {
        return orderDao.regionalDelivery();
    }

    @Override
    public List<EngineeringVo> thermalMap() {
        List<EngineeringVo> lis=  orderDao.thermalMap();
        return lis;
    }
}
